package fr.umlv.m2.jee.pmlv.web.homepage;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet wich represents the page where we can connect to website.
 * @author Alexandre
 */
public class Home extends HttpServlet {

    /**
     * @see HttpServlet#HttpServlet()
     */
    public Home() {
            super();
    }

    /**
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response).
    */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        doPost(request,response);
    }

    /**
    * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response).
    */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        boolean unknow = false;
        if(request.getParameter("unknow")!=null)
            unknow = true;

        //View
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

        out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">");
        out.println("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"fr\" >");

        out.println(" <head>");
        out.println("   <title>PMLV : Portail Universitaire de Marne-La-Vall&eacute;e</title>");
        out.println("   <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />");
        out.println("   <link rel=\"stylesheet\" media=\"screen\" type=\"text/css\" href=\"css/home.css\" />");
        out.println(" </head>");

        out.println(" <body>");
        out.println("   <div id=\"content\">");
        out.println("     <div id=\"title\"> PMLV </div>");

        out.println("     <ul>");
        out.println("       <li>Qu'est ce que \"PMLV\" ?</li>");
        out.println("       <div class=\"paragraph\">");
        out.println(
        "PMLV est une abr&eacute;viation pour \" Portail Universitaire de Marne-La-Vall&eacute;e\"." +
        "C'est un portail d'informations universitaire qui permet d'&eacute;changer diff&eacute;rentes informations entre les " +
        "diff&eacute;rents protagonistes d'une universit&eacute; tel que les &eacute;tudiants, les professeurs et le personnel administratif. " +
        "Les utilisateurs pourront, gr&acirc;ce &agrave; ce portail, aussi bien effectuer des actions administratives comme l'inscription " +
        "&agrave; une option ou bien encore effecteur des actions acad&eacute;miques comme l'acc&egrave;s au sujet d'un travail."
        );
        out.println("       </div>");
        out.println("       <li>Comment acc&eacute;der au portail \"PMLV\" ?</li>");

        out.println("       <div class=\"paragraph\">");
        out.println(
        "Pour se connecter au portail, il faut tout d'abord faire partie de l'Universit&eacute; de Marne-La-Vall&eacute;e." +
        "Ensuite &agrave; l'aide du login et mot de passe que l'on vous a fournit, vous pourrez vous connecter &agrave; " +
        "l'aide de l'espace de connection ci-dessus."
        );
        out.println("       </div>");

        out.println("       <li>Espace de connection :</li>");
        if(unknow)
            out.println("       <center class=\"error\">Votre login ou mot de passe n'est pas valide. Veuillez r&eacute;essayer.</center> ");
        else
            out.println("       <br/> ");

        out.println("       <form action=\"j_spring_security_check\" method=\"POST\" >");
        out.println("         <table cellspacing=\"6\">");
        out.println("           <tr>");
        out.println("             <td>Login :</td>");
        out.println("             <td><input type=text size=25 name=j_username></td>");
        out.println("           </tr>");

        out.println("           <tr>");
        out.println("             <td>Mot de passe :</td>");
        out.println("             <td><input type=password size=25 name=j_password></td>");
        out.println("           </tr>");
        out.println("           <tr>");
        out.println("             <td></td>");
        out.println("             <td id=\"formButton\"><input type=submit name=connecter value=Connecter></td>");
        out.println("           </tr>");
        out.println("         </table>");
        out.println("       </form>");
        out.println("     </ul>");
        out.println("   </div>");

        out.println("   <div id=\"footer\">");
        out.println("     <div id=\"copyright\">&copy; Universit&eacute; Paris-Est Marne-la-Vall&eacute;e</div>");
        out.println("     <div>PMLV v1.0 </div>");
        out.println("   </div>");
        out.println(" </body>");

        out.println("</html>");
        out.close();
    }
}
